<!DOCTYPE html>
<html lang="en">

<!-- Head tag -->
<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!--Description-->
    
        <meta name="description" content="创建组件 划分不同的功能不论是哪种方式创建出来的组件,组件的 template 属性指向的模板内容,只能有唯一的一个根元素1234567891011121314151617181920212223242526272829303132 &amp;lt;mycom1&amp;gt;&amp;lt;/mycom1&amp;gt;  Vu">
    

    <!--Author-->
    
        <meta name="author" content="John Doe">
    

    <!--Open Graph Title-->
    
        <meta property="og:title" content="Vue6-组件"/>
    

    <!--Open Graph Description-->
    

    <!--Open Graph Site Name-->
    <meta property="og:site_name" content="Hexo"/>

    <!--Type page-->
    
        <meta property="og:type" content="article" />
    

    <!--Page Cover-->
    

        <meta name="twitter:card" content="summary" />
    

    <!-- Title -->
    
    <title>Vue6-组件 - Hexo</title>

    <!-- Bootstrap Core CSS -->
    <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>

    <!-- Custom CSS -->
    <link rel="stylesheet" href="/css/style.css">

    <!-- Custom Fonts -->
    <link href="//maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet" type="text/css">
    <link href="//fonts.googleapis.com/css?family=Lora:400,700,400italic,700italic" rel="stylesheet" type="text/css">
    <link href="//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800" rel="stylesheet" type="text/css">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="//oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <script src="//oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

    <!-- Gallery -->
    <link href="//cdnjs.cloudflare.com/ajax/libs/featherlight/1.3.5/featherlight.min.css" type="text/css" rel="stylesheet" />

    <!-- Google Analytics -->
    


    <!-- favicon -->
    
	
</head>


<body>

    <!-- Menu -->
    <!-- Navigation -->
<nav class="navbar navbar-default navbar-custom navbar-fixed-top">
    <div class="container-fluid">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header page-scroll">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="/">逐风</a>
        </div>

        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <ul class="nav navbar-nav navbar-right">
                
                    <li>
                        <a href="/">
                            
                                Home
                            
                        </a>
                    </li>
                
                    <li>
                        <a href="/archives">
                            
                                Archives
                            
                        </a>
                    </li>
                
                    <li>
                        <a href="/tags">
                            
                                Tags
                            
                        </a>
                    </li>
                
                    <li>
                        <a href="/categories">
                            
                                Categories
                            
                        </a>
                    </li>
                
                    <li>
                        <a href="https://github.com/klugjo/hexo-theme-clean-blog">
                            
                                <i class="fa fa-github fa-stack-2x"></i>
                            
                        </a>
                    </li>
                
            </ul>
        </div>
        <!-- /.navbar-collapse -->
    </div>
    <!-- /.container -->
</nav>

    <!-- Main Content -->
    <!-- Page Header -->
<!-- Set your background image for this header in your post front-matter: cover -->

<header class="intro-header" style="background-image: url('http://www.codeblocq.com/assets/projects/hexo-theme-clean-blog/img/home-bg.jpg')">
    <div class="container">
        <div class="row">
            <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                <div class="post-heading">
                    <h1>Vue6-组件</h1>
                    
                    <span class="meta">
                        <!-- Date and Author -->
                        
                        
                            2017-10-23
                        
                    </span>
                </div>
            </div>
        </div>
    </div>
</header>

<!-- Post Content -->
<article>
    <div class="container">
        <div class="row">

            <!-- Tags and categories -->
           

            <!-- Gallery -->
            

            <!-- Post Main Content -->
            <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                <p>创建组件 划分不同的功能<br>不论是哪种方式创建出来的组件,组件的 template 属性指向的模板内容,只能有唯一的一个根元素<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div></pre></td><td class="code"><pre><div class="line"> &lt;mycom1&gt;&lt;/mycom1&gt;</div><div class="line"> </div><div class="line"> Vue.component(&apos;mycom1&apos;, Vue.extend(&#123;</div><div class="line">      template: &apos;&lt;h3&gt;这是使用 Vue.extend 创建的组件&lt;/h3&gt;&apos;</div><div class="line">    &#125;))</div><div class="line">	</div><div class="line">var com1 = Vue.extend(&#123;</div><div class="line">      template: &apos;&lt;h3&gt;这是使用 Vue.extend 创建的组件&lt;/h3&gt;&apos; // 通过 template 属性，指定了组件要展示的HTML结构</div><div class="line">    &#125;)</div><div class="line">Vue.component(&apos;myCom1&apos;, com1)</div><div class="line"></div><div class="line">创建私有组件</div><div class="line"> &lt;login&gt;&lt;/login&gt;</div><div class="line">&lt;template id=&quot;tmpl2&quot;&gt;</div><div class="line">    &lt;h1&gt;这是私有的 login 组件&lt;/h1&gt;</div><div class="line">  &lt;/template&gt;</div><div class="line"></div><div class="line"> components: &#123; // 定义实例内部私有组件的</div><div class="line">        login: &#123;</div><div class="line">          template: &apos;#tmpl2&apos;</div><div class="line">        &#125;	</div><div class="line">	</div><div class="line">组件中的 data 必须是一个函数，返回一个对象，</div><div class="line">Vue.component(&apos;mycom1&apos;, &#123;</div><div class="line">      template: &apos;&lt;h1&gt;这是全局组件 --- &#123;&#123;msg&#125;&#125;&lt;/h1&gt;&apos;,</div><div class="line">      data: function () &#123;</div><div class="line">        return &#123;</div><div class="line">          msg: &apos;这是组件的中data定义的数据&apos;</div><div class="line">        &#125;</div><div class="line">      &#125;</div><div class="line">    &#125;)	</div><div class="line">```</div></pre></td></tr></table></figure></p>
<p>组件切换(tap切换效果)<br>加动画版<br> <style><br>    .v-enter,<br>    .v-leave-to {<br>      opacity: 0;<br>      transform: translateX(150px);<br>    }</p>
<pre><code>.v-enter-active,
.v-leave-active {
  transition: all 0.5s ease;
}
</code></pre><p>  </style><br> <figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line">```</div><div class="line"> &lt;div id=&quot;app&quot;&gt;</div><div class="line">    &lt;a href=&quot;&quot; @click.prevent=&quot;comName=&apos;login&apos;&quot;&gt;登录&lt;/a&gt;</div><div class="line">    &lt;a href=&quot;&quot; @click.prevent=&quot;comName=&apos;register&apos;&quot;&gt;注册&lt;/a&gt;</div><div class="line"></div><div class="line">    &lt;!-- 通过 mode 属性,设置组件切换时候的 模式 --&gt;</div><div class="line">	transition 属性 mode=out-in  设置过渡状态，一个动画完成另一个动画再开始</div><div class="line">    &lt;transition mode=&quot;out-in&quot;&gt;</div><div class="line">	    &lt;!-- component 一个占位符, :is 属性,可以用来指定要展示的组件的名称 --&gt;</div><div class="line">      &lt;component :is=&quot;comName&quot;&gt;&lt;/component&gt;</div><div class="line">    &lt;/transition&gt;</div><div class="line"></div><div class="line">  &lt;/div&gt;</div></pre></td></tr></table></figure></p>
<pre><code>Vue.component(&apos;login&apos;, {
     template: &apos;&lt;h3&gt;登录组件&lt;/h3&gt;&apos;
   })

   Vue.component(&apos;register&apos;, {
     template: &apos;&lt;h3&gt;注册组件&lt;/h3&gt;&apos;
   })
   var vm = new Vue({
     el: &apos;#app&apos;,
     data: {
       comName: &apos;login&apos; // 当前 component 中的 :is 绑定的组件的名称
     },
     methods: {}
   });
</code></pre>

                
            </div>

            <!-- Comments -->
            
                <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                    


                </div>
            
        </div>
    </div>
</article>

    <!-- Footer -->
    <hr />

<!-- Footer -->
<footer>
    <div class="container">
        <div class="row">
            <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                <ul class="list-inline text-center">
                    

                    

                    
                        <li>
                            <a href="https://github.com/klugjo/hexo-theme-clean-blog" target="_blank">
                                <span class="fa-stack fa-lg">
                                    <i class="fa fa-circle fa-stack-2x"></i>
                                    <i class="fa fa-github fa-stack-1x fa-inverse"></i>
                                </span>
                            </a>
                        </li>
                    

                    

                    

                    
                </ul>
                <p class="copyright text-muted">&copy; 2018 John Doe<br></p>
                <p class="copyright text-muted">Original Theme <a target="_blank" href="http://startbootstrap.com/template-overviews/clean-blog/">Clean Blog</a> from <a href="http://startbootstrap.com/" target="_blank">Start Bootstrap</a></p>
                <p class="copyright text-muted">Adapted for <a target="_blank" href="https://hexo.io/">Hexo</a> by <a href="http://www.codeblocq.com/" target="_blank">Jonathan Klughertz</a></p>
            </div>
        </div>
    </div>
</footer>


    <!-- After footer scripts -->
    
<!-- jQuery -->
<script src="//code.jquery.com/jquery-2.1.4.min.js"></script>

<!-- Bootstrap -->
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

<!-- Gallery -->
<script src="//cdnjs.cloudflare.com/ajax/libs/featherlight/1.3.5/featherlight.min.js" type="text/javascript" charset="utf-8"></script>

<!-- Disqus Comments -->



</body>

</html>